#include "mainwindow.h"
#include <QTabWidget>
#include <QTreeView>
#include <QTableView>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSplitter>
#include <QListWidget>
#include <QGraphicsView>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    createWidget();
    createLayout();
    createConnection();
}

MainWindow::~MainWindow()
{
}

void MainWindow::createWidget()
{
    //QMainWindow不能增加添加布局，所以先定义一个QWidget
    m_pMainWidget = new QWidget(this);
    //把定义的QWidget设置为当前QMainWindow的主窗口
    this->setCentralWidget(m_pMainWidget);
    m_pTabWidget = new QTabWidget(m_pMainWidget);
    m_pTreeView = new QTreeView(m_pMainWidget);
    m_pTableView = new QTableView(m_pMainWidget);
    m_pImgView = new QGraphicsView(m_pMainWidget);
    m_pInfoWidget = new QListWidget(m_pMainWidget);
    m_pMainLayout = new QVBoxLayout(m_pMainWidget);
    m_pAddWidget = new QWidget(m_pTabWidget);
    m_pManagerWidget = new QWidget(m_pTabWidget);
    //添加2个选项卡窗口
    m_pTabWidget->addTab(m_pAddWidget, ("添加"));
    m_pTabWidget->addTab(m_pManagerWidget, ("管理"));

    showMaximized();
}

void MainWindow::createLayout()
{
    QHBoxLayout *pViewLayout = new QHBoxLayout(m_pMainWidget);
    //水平分裂器
    QSplitter *pHSplitter = new QSplitter(m_pMainWidget);
    pHSplitter->setOrientation(Qt::Horizontal);
    //垂直分裂器
    QSplitter *pVSplitter = new QSplitter(pHSplitter);
    pVSplitter->setOrientation(Qt::Vertical);

    //向垂直分裂器添加2个控件
    pVSplitter->addWidget(m_pImgView);
    pVSplitter->addWidget(m_pInfoWidget);

    //给水平分裂器添加3个控件,3个控件的比例
    pHSplitter->addWidget(m_pTreeView);
    pHSplitter->addWidget(m_pTableView);
    pHSplitter->addWidget(pVSplitter);
    //3个控件的比例的比例分别为2:8:2
    pHSplitter->setStretchFactor(0, 2);
    pHSplitter->setStretchFactor(1, 8);
    pHSplitter->setStretchFactor(2, 2);

    //把水平分裂器添加到水平布局中
    pViewLayout->addWidget(pHSplitter);

    QHBoxLayout *pTopLayout = new QHBoxLayout(m_pMainWidget);
    //把选项卡控件添加到顶部的水平布局中
    pTopLayout->addWidget(m_pTabWidget);

    //把顶部水平布局和下部垂直布局添加到主垂直布局中
    m_pMainLayout->addLayout(pTopLayout);
    m_pMainLayout->addLayout(pViewLayout);

    //设置顶部和下部的比例为1:12
    m_pMainLayout->setStretchFactor(pTopLayout, 1);
    m_pMainLayout->setStretchFactor(pViewLayout, 12);

    m_pMainWidget->setLayout(m_pMainLayout);
}

void MainWindow::createConnection()
{

}
